--
-- Author: shunguo.chen
-- Date: 2019-07-04 16:19:02
--
-- TeamMatchCrossController 跨服匹配
--

local TeamMatchCrossView = import("..views.TeamMatchCrossView")

local fileName = string.getModeName(...)
local ClassRef = class(fileName, app.mvc.ControllerBase)

function ClassRef:ctor(data)
    self.super.ctor(self, data)
end

function ClassRef:init()
    self._model = app:getInst("TeamModel")

end

function ClassRef:removeListeners()
    self.super.removeListeners(self)

end

function ClassRef:listEvent()
    return { }
end


function ClassRef:openView(data)
    if nil == self._view then
        self._view = TeamMatchCrossView.new(app.mvc.VIEWTYPE_BLUR)
        self._view:onCloseView(handler(self, self.closeView))
        self._view:onClearView(handler(self, self.clearView))
        self._view:onOperate(handler(self, self.onOperate))
        self:addChild(self._view, {notDelete=true})
    end

    self._view:show()
    self._view:refresh(self._model:getTeamMatchCrossInfo())
end
function ClassRef:clearView()
    if self._view then
        self._view = nil
    end
end

-------------------------------------------------------


-------------------------------------------------------
function ClassRef:onOperate(op, data)
    print("TeamMatchCrossController:onOperate op", op)
    if op == "match_confirm" then
        -- 确认匹配 data = 是否确认
        if data then
            self._model:C2S_CrossDungeonMatchConfirm(data)
        else
            local dlg = display.newConfirmDialog( L("CrossServerTips25"),
                function() -- 确定
                    self._model:C2S_CrossDungeonMatchConfirm(data)
                end)
            UIHandler:addPopDialog( dlg )
        end
    end
end

return ClassRef
